home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / fly8111-.000 / fly8111- / fly8 / field.c < prev    next >
C/C++ Source or Header  |  1979-12-31  |  2KB  |  79 lines

  1. /* --------------------------------- field.c -------------------------------- */
  2.  
  3. /* This is part of the flight simulator 'fly8'.
  4.  * Author: Eyal Lebedinsky (eyal@ise.canberra.edu.au).
  5. */
  6.  
  7. /* Read a field from a file, used for reading all input files.
  8. */
  9.  
  10. #include "fly.h"
  11.  
  12.  
  13. extern int FAR
  14. field_find (FILE *ifile, char *line)
  15. {
  16.     do {
  17.         fgets (line, 256, ifile);
  18.         if (ferror (ifile)) {
  19.             LogPrintf ("%s %ld: nav read error\n",
  20.                 st.filename, st.lineno);
  21.             return (-1);
  22.         }
  23.         ++st.lineno;
  24.     } while ('\n' == line[0] || '#' == line[0]);
  25.     return (0);
  26. }
  27.  
  28. extern int FAR
  29. field_long (FILE *ifile, char *line, long *value)
  30. {
  31.     long    l;
  32.  
  33.     if (field_find (ifile, line))
  34.         return (-1);
  35.     if (1 != sscanf (line, "%ld", &l)) {
  36.         LogPrintf ("bad number at line %ld: %s\n",
  37.             st.lineno, st.filename);
  38.         return (-1);
  39.     }
  40.     *value = l;
  41.     return (0);
  42. }
  43.  
  44. extern int FAR
  45. field_read (FILE *ifile, struct FldTab FAR *fld, char * line)
  46. {
  47.     long    t;
  48.     char    s[80];
  49.  
  50.     if (field_find (ifile, line))
  51.         return (-1);
  52.  
  53.     if (READ_S & fld->type) {        /* string */
  54.         if (1 != sscanf (line, "\"%[^\"]", s)) {
  55.             LogPrintf ("%s %ld: bad field data\n",
  56.                 st.filename, st.lineno);
  57.             return (-1);
  58.         }
  59.         *(char **)(fld->p) = STRdup (s);
  60.         return (0);
  61.     }
  62.  
  63.     if (1 != sscanf (line, "%ld", &t)) {
  64.         LogPrintf ("%s %ld: bad field data\n",
  65.             st.filename, st.lineno);
  66.         return (-1);
  67.     }
  68.  
  69.     if (READ_I+4 == fld->type)
  70.         *(long *)(fld->p) = t;
  71.     else if (READ_I+2 == fld->type)
  72.         *(short *)(fld->p) = (short)t;
  73.     else if (READ_I+1 == fld->type)
  74.         *(short *)(fld->p) = (short)t;
  75.     else
  76.         return (-1);
  77.     return (0);
  78. }
  79.